package org.xrebel.configure;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.xrebel.support.MybatisXmlReload;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * xrebel 项目配置类
 *
 * @author 李坤
 * @date 2024/3/21 13:52
 */
@Configuration
@ComponentScan(basePackages = "org.xrebel")
public class XrebelConfigure {

    @Resource
    private XrebelProperties xrebelProperties;

    @Bean
    public MybatisXmlReload mybatisXmlReload(List<SqlSessionFactory> sqlSessionFactories) throws IOException {
        final MybatisXmlReload mybatisXmlReload = new MybatisXmlReload(xrebelProperties, sqlSessionFactories);
        if (xrebelProperties.isEnabled()) {
            mybatisXmlReload.createMybatisXmlReloadTask();
        }
        return mybatisXmlReload;
    }

}
